﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;

namespace QuickExcel
{
    public partial class ImportFileSheetOptions : Form
    {
        Excel.Workbook wb;
        string sRange;
            
        public ImportFileSheetOptions(string file,string sRng)
        {
            InitializeComponent();
            if(Globals.ThisAddIn.Application.ActiveSheet.Range(sRng).Text.Length == 0)
                Globals.ThisAddIn.Application.ActiveSheet.Range(sRng).Value2 = "";
            
            wb = Globals.ThisAddIn.Application.Workbooks.Open(file, false, true);
            Globals.ThisAddIn.Application.Windows[wb.Name].Visible = false;
            //wb.Windows[1].Visible = false;
            
            for (int counter = 1; counter <= wb.Sheets.Count; counter++)
            {
                listSheets.Items.Add(wb.Sheets[counter].Name);
            }
            sRange = sRng;
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            wb.Sheets[listSheets.Text].UsedRange.Copy();
            Globals.ThisAddIn.Application.ActiveSheet.Range(sRange).PasteSpecial(Excel.XlPasteType.xlPasteAll);
            Globals.ThisAddIn.Application.ActiveSheet.Range(sRange).Cells[1, 1].Select();

            wb.Close(false);
            this.Close();
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
